package com.weasel.weixin.commons.message.builder;

import com.weasel.weixin.commons.message.bean.WeiXinPostCommonXmlAnswerArticleMessage;

/**
 * Created by Dylan on 2015/10/12.
 */
public class WeixinPostCommonXmlAnswerArticleMessageBuilder extends AbstractWeixinPostCommonXmlAnswerMessageBuilder<WeixinPostCommonXmlAnswerArticleMessageBuilder,WeiXinPostCommonXmlAnswerArticleMessage>{


    public WeixinPostCommonXmlAnswerArticleMessageBuilder() {
        super(new WeiXinPostCommonXmlAnswerArticleMessage());
    }

    public WeixinPostXmlAnswerArticleBodyMessageBuilder addArticle(){

        return new WeixinPostXmlAnswerArticleBodyMessageBuilder(this);
    }


    public static class WeixinPostXmlAnswerArticleBodyMessageBuilder{

        private WeixinPostCommonXmlAnswerArticleMessageBuilder parent;

        private WeiXinPostCommonXmlAnswerArticleMessage.ArticleBody body = new WeiXinPostCommonXmlAnswerArticleMessage.ArticleBody();

        public WeixinPostXmlAnswerArticleBodyMessageBuilder(){
        }

        public WeixinPostXmlAnswerArticleBodyMessageBuilder(WeixinPostCommonXmlAnswerArticleMessageBuilder _parent){

            this.parent = _parent;
        }

        public WeixinPostXmlAnswerArticleBodyMessageBuilder title(String title){

            body.setTitle(title);
            return this;
        }

        public WeixinPostXmlAnswerArticleBodyMessageBuilder description(String description){

            body.setDescription(description);
            return this;
        }

        public WeixinPostXmlAnswerArticleBodyMessageBuilder picUrl(String picUrl){

            body.setPicUrl(picUrl);
            return this;
        }

        public WeixinPostXmlAnswerArticleBodyMessageBuilder url(String url){
             body.setUrl(url);
            return this;
        }

        public WeixinPostCommonXmlAnswerArticleMessageBuilder end(){

            if(null == parent){
                throw new RuntimeException("请调用带参的构造方法，并传递WeixinPostCommonXmlAnswerArticleMessageBuilder参数，否则请调用build方法");
            }
            ((WeiXinPostCommonXmlAnswerArticleMessage)parent.message).addArticle(build());
            return parent;
        }

        public WeiXinPostCommonXmlAnswerArticleMessage.ArticleBody build(){
            return body;
        }

    }
}
